**************************************************************
*FUEL SUBSIDY PASS-THROUGH AND MARKET STRUCTURE 
* DATA PREPARATION   
**************************************************************
*CONSTRUCTING RIN IMPLICIT TAX/SUBSIDY
* Notes: - Until EPA released 2014-2016 FR, only relevant rule that was in place 
*			was the 2013 FR. 2014-2016 FR was released on 11/30/2015, so adjust
*           the tax after that date to reflect 2015 % standards. 
* 		 - 2013 Standards: 
*			BBD=1.13%
*			ADV=1.62%
*			REN=9.74%
* 		 - 2015 Standards: 
*			BBD=1.49%
*			ADV=1.62%
*			REN=9.52%
* 		 - 2016 Standards: 
*			BBD=1.59%
*			ADV=2.01%
*			REN=10.10%
*  		 - E85 blending is seasonal and depends on the region in the US. 
*           According to the DOE, blending can range from 51%-83% depending on
*           the region and time of year. 
*        - Class blending minimum ethanol content specifications:
*           Class 1 (Summer) = 79%
*			Class 2 (Spring/Fall) = 74%
*           Class 3/4 (Winter) = 70%/68%
*        -IA/IL/MN Classes (roughly)
*           Nov-Mar = 3/4
*			Apr-May & Sept-Oct = 2
* 			June-Aug = 1
********************************************* 

****
*Select & Construct Ethanol, Gasoline, and E85 Wholesale Prices
gen eth_whole=eth_whole1
label var eth_whole "Ethanol Wholesale Costs"	

gen eth_whole_adj=0.68*eth_whole if month>=11|month<=3
	replace eth_whole_adj=0.74*eth_whole if month==4|month==5|month==9|month==10
	replace eth_whole_adj=0.79*eth_whole if month==6|month==7|month==8
label var eth_whole_adj "Adj. Ethanol Wholesale Costs"	
	
gen gas_whole=gas_whole2
label var gas_whole "Gasoline Wholesale Costs"	

gen gas_whole_adj=0.32*gas_whole if month>=11|month<=3
	replace gas_whole_adj=0.26*gas_whole if month==4|month==5|month==9|month==10
	replace gas_whole_adj=0.21*gas_whole if month==6|month==7|month==8
label var gas_whole_adj "Adj. Ethanol Wholesale Costs"
	
gen e85_whole=(1-0.68)*gas_whole+0.68*eth_whole if month>=11|month<=3
	replace e85_whole=(1-0.74)*gas_whole+0.74*eth_whole if month==4|month==5|month==9|month==10
	replace e85_whole=(1-0.79)*gas_whole+0.79*eth_whole if month==6|month==7|month==8
label var e85_whole "E85 Wholesale Costs"	
	
****
*Gas Tax
*2013 Standards
gen tax_e0= 0.0113*prin_bio + ///
			(0.0162-0.0113)*prin_adv + ///
			(0.0974-0.0162)*prin_eth if yw<=2907
*2015 Standards
replace tax_e0 = 0.0149*prin_bio + ///
			(0.0162-0.0149)*prin_adv + ///
			(0.0952-0.0162)*prin_eth if yw>2907 & yw<2912
*2016 Standards
replace tax_e0 = 0.0159*prin_bio + ///
			(0.0201-0.0159)*prin_adv + ///
			(0.101-0.0201)*prin_eth if yw>=2912
	label var tax_e0 "Gas Tax"
	
****
*Ethanol Subsidy	
gen sub_eth=prin_eth
	label var sub_eth "Ethanol Subsidy"
	
****
*E85 Subsidy
* Notes: - Assumes pass-through of RIN to RBOB prices. 
gen sub_e85=-0.68*sub_eth if month>=11|month<=3
	replace sub_e85=-0.74*sub_eth if month==4|month==5|month==9|month==10
	replace sub_e85=-0.79*sub_eth if month==6|month==7|month==8
	label var sub_e85 "E85 Subsidy"	

****
*Distance Indicators
gen dist2=0
	replace dist2=1 if min_dist_df>=2
gen dist5=0
	replace dist5=1 if min_dist_df>=5
gen dist10=0
	replace dist10=1 if min_dist_df>=10
gen dist15=0
	replace dist15=1 if min_dist_df>=15
	
*Generating constant for certain specifications
gen cons=1

****
*First differenced model interaction variables
*E85 Subsidy
gen pt_dsub_l8=L8.D.sub_e85
forval i=0/7 {
	gen d2sub_l`i'=L`i'.D2.sub_e85
}
*
*E85 Subsidy X Branded Major
gen pt_dsub_brand_l8=L8.D.sub_e85*brand_maj
forval i=0/7 {
	gen d2sub_brand_l`i'=L`i'.D2.sub_e85*brand_maj
}
*
*E85 Subsidy X Major Retailer
gen pt_dsub_retail_l8=L8.D.sub_e85*ret_maj
forval i=0/7 {
	gen d2sub_retail_l`i'=L`i'.D2.sub_e85*ret_maj
}
*
*E85 Subsidy X Distance > 2 Miles
gen pt_dsub_dist2_l8=L8.D.sub_e85*dist2
forval i=0/7 {
	gen d2sub_dist2_l`i'=L`i'.D2.sub_e85*dist2
}
*
*E85 Subsidy X Distance > 5 Miles
gen pt_dsub_dist5_l8=L8.D.sub_e85*dist5
forval i=0/7 {
	gen d2sub_dist5_l`i'=L`i'.D2.sub_e85*dist5
}
*
*E85 Subsidy X Distance > 10 Miles
gen pt_dsub_dist10_l8=L8.D.sub_e85*dist10
forval i=0/7 {
	gen d2sub_dist10_l`i'=L`i'.D2.sub_e85*dist10
}
*
*E85 Subsidy X Distance > 15 Miles
gen pt_dsub_dist15_l8=L8.D.sub_e85*dist15
forval i=0/7 {
	gen d2sub_dist15_l`i'=L`i'.D2.sub_e85*dist15
}
*
*E85 Wholesale
gen pt_de85_l8=L8.D.e85_whole
forval i=0/7 {
	gen d2e85_l`i'=L`i'.D2.e85_whole
}
*
*E85 Wholesale X Branded Major
gen pt_de85_brand_l8=L8.D.e85_whole*brand_maj
forval i=0/7 {
	gen d2e85_brand_l`i'=L`i'.D2.e85_whole*brand_maj
}
*
*E85 Wholesale X Major Retailer
gen pt_de85_retail_l8=L8.D.e85_whole*ret_maj
forval i=0/7 {
	gen d2e85_retail_l`i'=L`i'.D2.e85_whole*ret_maj
}
*
*E85 Wholesale X Distance > 2 Miles
gen pt_de85_dist2_l8=L8.D.e85_whole*dist2
forval i=0/7 {
	gen d2e85_dist2_l`i'=L`i'.D2.e85_whole*dist2
}
*
*E85 Wholesale X Distance > 5 Miles
gen pt_de85_dist5_l8=L8.D.e85_whole*dist5
forval i=0/7 {
	gen d2e85_dist5_l`i'=L`i'.D2.e85_whole*dist5
}
*
*E85 Wholesale X Distance > 10 Miles
gen pt_de85_dist10_l8=L8.D.e85_whole*dist10
forval i=0/7 {
	gen d2e85_dist10_l`i'=L`i'.D2.e85_whole*dist10
}
**E85 Wholesale X Distance > 15 Miles
gen pt_de85_dist15_l8=L8.D.e85_whole*dist15
forval i=0/7 {
	gen d2e85_dist15_l`i'=L`i'.D2.e85_whole*dist15
}
*
****
*Levels model interaction variables
*E85 Subsidy
gen pt_sub_l8=L8.sub_e85
forval i=0/7 {
	gen dsub_l`i'=L`i'.D.sub_e85
}
*
*E85 Subsidy X Branded Major
gen pt_sub_brand_l8=L8.sub_e85*brand_maj
forval i=0/7 {
	gen dsub_brand_l`i'=L`i'.D.sub_e85*brand_maj
}
*
*E85 Subsidy X Major Retailer
gen pt_sub_retail_l8=L8.sub_e85*ret_maj
forval i=0/7 {
	gen dsub_retail_l`i'=L`i'.D.sub_e85*ret_maj
}
*
*E85 Subsidy X Distance > 2 Miles
gen pt_sub_dist2_l8=L8.sub_e85*dist2
forval i=0/7 {
	gen dsub_dist2_l`i'=L`i'.D.sub_e85*dist2
}
*
*E85 Subsidy X Distance > 5 Miles
gen pt_sub_dist5_l8=L8.sub_e85*dist5
forval i=0/7 {
	gen dsub_dist5_l`i'=L`i'.D.sub_e85*dist5
}
*
*E85 Subsidy X Distance > 10 Miles
gen pt_sub_dist10_l8=L8.sub_e85*dist10
forval i=0/7 {
	gen dsub_dist10_l`i'=L`i'.D.sub_e85*dist10
}
*
*E85 Subsidy X Distance > 15 Miles
gen pt_sub_dist15_l8=L8.sub_e85*dist15
forval i=0/7 {
	gen dsub_dist15_l`i'=L`i'.D.sub_e85*dist15
}
*
*E85 Wholesale
gen pt_e85_l8=L8.e85_whole
forval i=0/7 {
	gen de85_l`i'=L`i'.D.e85_whole
}
*
*E85 Wholesale X Branded Major
gen pt_e85_brand_l8=L8.e85_whole*brand_maj
forval i=0/7 {
	gen de85_brand_l`i'=L`i'.D.e85_whole*brand_maj
}
*
*E85 Wholesale X Major Retailer
gen pt_e85_retail_l8=L8.e85_whole*ret_maj
forval i=0/7 {
	gen de85_retail_l`i'=L`i'.D.e85_whole*ret_maj
}
*
*E85 Wholesale X Distance > 2 Miles
gen pt_e85_dist2_l8=L8.e85_whole*dist2
forval i=0/7 {
	gen de85_dist2_l`i'=L`i'.D.e85_whole*dist2
}
*
*E85 Wholesale X Distance > 5 Miles
gen pt_e85_dist5_l8=L8.e85_whole*dist5
forval i=0/7 {
	gen de85_dist5_l`i'=L`i'.D.e85_whole*dist5
}
*
*E85 Wholesale X Distance > 10 Miles
gen pt_e85_dist10_l8=L8.e85_whole*dist10
forval i=0/7 {
	gen de85_dist10_l`i'=L`i'.D.e85_whole*dist10
}
*
*E85 Wholesale X Distance > 15 Miles
gen pt_e85_dist15_l8=L8.e85_whole*dist15
forval i=0/7 {
	gen de85_dist15_l`i'=L`i'.D.e85_whole*dist15
}
*
